package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysMenuDTO;
import com.rabbit.eap.system.entity.SysMenu;
import com.rabbit.eap.system.param.SysMenuPageParam;
import com.rabbit.eap.system.service.ISysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysMenuController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 菜单 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysMenu")
@Module("system")
@Api(value = "菜单API", tags = {"菜单"})
public class SysMenuController extends BaseController {

    @Autowired
    private ISysMenuService sysMenuService;


    /**
    * @Description: 添加菜单
    * @methodName: saveSysMenu
    * @param sysMenuDTO:sysMenuDTO数据传输对象
    * @return: ApiResult.result(flag)
    * @date: 2020/06/06 23:05:26
    * @author: rabbit
    */
    @PostMapping("/saveSysMenu")
    @RequiresPermissions("sys:menu:add")
    @OperationLog(name = "添加菜单", type = OperationLogType.ADD)
    @ApiOperation(value = "添加菜单", response = ApiResult.class)
    public ApiResult saveSysMenu(@Validated(AddGroup.class) @RequestBody SysMenuDTO sysMenuDTO) throws Exception {
        ApiResult apiResult = sysMenuService.saveSysMenu(sysMenuDTO);
        return apiResult;
    }
    /**
     * @Description: 修改菜单
     * @methodName: modifySysMenu
     * @param  sysMenuDTO:sysMenuDTO数据传输对象
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysMenu")
    @RequiresPermissions("sys:menu:edit")
    @OperationLog(name = "修改菜单", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改菜单", response = ApiResult.class)
    public ApiResult modifySysMenu(@Validated(UpdateGroup.class) @RequestBody SysMenuDTO sysMenuDTO) throws Exception {
        ApiResult  apiResult = sysMenuService.modifySysMenu(sysMenuDTO);
        return apiResult;
    }
    /**
     * @Description: 删除菜单
     * @methodName: removeSysMenu
     * @param menuId:菜单Id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysMenu")
    @RequiresPermissions("sys:menu:remove")
    @OperationLog(name = "删除菜单", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除菜单", response = ApiResult.class)
    public ApiResult  removeSysMenu(@RequestParam("menuId") Long menuId) throws Exception {
        ApiResult  apiResult = sysMenuService.removeSysMenu(menuId);
        return apiResult;
    }

    /**
     * @Description: 根据Id获取菜单详情
     * @methodName: getSysMenuInfo
     * @param id: id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysMenuInfo")
    @RequiresPermissions("sys:menu:query")
    @OperationLog(name = "菜单详情", type = OperationLogType.INFO)
    @ApiOperation(value = "菜单详情", response = ApiResult.class)
    public ApiResult getSysMenuInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysMenuService.getSysMenuById(id);
        return apiResult;
    }

    /**
     * @Description: 菜单分页列表
     * @methodName: getSysMenuPageList
     * @param sysMenuPageParam
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PostMapping("/getSysMenuPageList")
    @RequiresPermissions("sys:menu:list")
    @OperationLog(name = "菜单分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "菜单分页列表", response = ApiResult.class)
    public ApiResult getSysMenuPageList(@Validated @RequestBody SysMenuPageParam sysMenuPageParam) throws Exception {
        ApiResult  apiResult = sysMenuService.getSysMenuPageList(sysMenuPageParam);
        return apiResult;
    }

    /**
     * @Description: 获取角色菜单树
     * @methodName: getRoleMenuTree
     * @param roleId: 角色Id
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/29 20:40
     * @author: rabbit
     *
     */
    @GetMapping("/getRoleMenuTree")
    @OperationLog(name = "获取角色菜单树", type = OperationLogType.LIST)
    @ApiOperation(value = "获取角色菜单树", response = ApiResult.class)
    public ApiResult getRoleMenuTree(@RequestParam("roleId") Long roleId){
       ApiResult  apiResult=  sysMenuService.getRoleMenuTree(roleId);
       return apiResult;
    }
    /**
     * @Description: 获取菜单列表
     * @methodName: getSysMenuList
     * @param sysMenu:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/29 21:18
     * @author: rabbit
     *
     */
    @GetMapping("/getSysMenuList")
    @OperationLog(name = "菜单列表", type = OperationLogType.LIST)
    @ApiOperation(value = "菜单列表", response = ApiResult.class)
    public ApiResult  getSysMenuList(SysMenu sysMenu){
        ApiResult apiResult = sysMenuService.getSysMenuList(sysMenu);
        return apiResult;
    }

    /**
     * @Description: 获取所有菜单
     * @methodName: getSysMenuAll
     * @param sysMenu:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/29 21:18
     * @author: rabbit
     *
     */
    @RequiresPermissions("sys:menu:query")
    @GetMapping("/getSysMenuAll")
    @OperationLog(name = "菜单列表", type = OperationLogType.LIST)
    @ApiOperation(value = "菜单列表", response = ApiResult.class)
    public ApiResult  getSysMenuAll(SysMenu sysMenu){
        ApiResult apiResult = sysMenuService.getSysMenuAll(sysMenu);
        return apiResult;
    }

    /**
     * @Description: 获取菜单下拉树列表
     * @methodName: getTreeMenu
     * @param sysMenu:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/6/29 21:25
     * @author: rabbit
     *
     */
    @GetMapping("/getTreeMenu")
    @OperationLog(name = "获取菜单下拉树列表", type = OperationLogType.LIST)
    @ApiOperation(value = "获取菜单下拉树列表", response = ApiResult.class)
    public ApiResult getTreeMenu(SysMenu sysMenu){
        ApiResult apiResult =  sysMenuService.getTreeMenu(sysMenu);
        return apiResult;
    }
    /**
     * @Description: 获取角色菜单权限
     * @methodName: getRoleMenu
     * @param roleId: 角色id
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/10/6 17:05
     * @author: rabbit
     *
     */
    @GetMapping("/getRoleMenu/{roleId}")
    @OperationLog(name = "获取角色菜单", type = OperationLogType.LIST)
    @ApiOperation(value = "获取角色菜单", response = ApiResult.class)
    public ApiResult getRoleMenu(@PathVariable("roleId") Long  roleId){
        ApiResult apiResult = sysMenuService.getRoleMenu(roleId);
        return apiResult;
    }
}

